//
//  NEDCollectionTestViewController.m
//  NEDFormView_Example
//
//  Created by 000 on 2022/1/10.
//  Copyright © 2022 000. All rights reserved.
//

#import "NEDCollectionTestViewController.h"
#import <NEDStyle/UIColor+NEDStyle.h>
#import <Masonry/Masonry.h>
#import <NEDConstant/NEDConstant.h>
#import "NEDFormTargetCollectionView.h"

@interface NEDCollectionTestViewController ()<UICollectionViewDelegate, UICollectionViewDataSource,NEDFormCollectionViewProtocol>

@property (retain, nonatomic) UICollectionView * collectionView;

@property (retain, nonatomic) NEDFormTargetCollectionView * targetForm;

@end

@implementation NEDCollectionTestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"Form collectionview list";
    
    WS(weakSelf)
    
    UICollectionViewFlowLayout * flowLayout = [UICollectionViewFlowLayout new];
    flowLayout.minimumLineSpacing = 3;
    flowLayout.minimumInteritemSpacing = 3;
    flowLayout.itemSize = CGSizeMake(CGRectGetWidth(self.view.frame), 60);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    /// 注册target 绑定tableview 的delegate和datasource
    NEDFormTargetCollectionView * targetForm = [[NEDFormTargetCollectionView alloc] initWithCollectionView:self.collectionView];
    self.targetForm = targetForm;
    targetForm.rowDelegate = self;

    NEDFormItem * item = NEDFormInitSpace(20);
    [targetForm addOptionItem:item];

    item = NEDFormInitTitleCenter(@"标题设置");
    item.layout.showBottomSeparatorLine = YES;
    [targetForm addOptionItem:item];

    item = NEDFormInitTitleLeft(@"左边标题").showRightArrow;
    [item.rowDataList addObjectsFromArray:@[@"111",@"111",@"111",@"111",@"111",@"222",@"222",@"222",@"222",@"222",@"222",@"222",@"222",@"3333",@"3333",@"3333",@"3333"]];
    [targetForm addOptionItem:item];

    item = NEDFormInitTitleLeftRight(@"左标题", @"右描述");
    [targetForm addOptionItem:item];

    //分割线
    item = NEDFormInitSpace(20);
    item.layout.backgroundColor = UIColor.ned_separator.ned_alpha(0.5);
    item.layout.isNotUpdateLayoutFromArrayUnifiedSettings = YES;
    [targetForm addOptionItem:item];


    targetForm.dataList.form_marginLeft(30).form_marginRight(30);

    [targetForm reloadContentView];
    
    [self.collectionView registerClass:UICollectionViewCell.class forCellWithReuseIdentifier:@"cell"];
}

//- (CGSize)form_collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath sectionItem:(NEDFormItem *)sectionItem rowItem:(id)rowItem{
//    return CGSizeMake(<#CGFloat width#>, <#CGFloat height#>);
//}

-(__kindof UICollectionViewCell *)form_collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath sectionItem:(NEDFormItem *)sectionItem rowItem:(id)rowItem{
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    cell.backgroundColor = UIColor.ned_randomColor;
    
    return cell;
}

-(void)form_collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath sectionItem:(NEDFormItem *)sectionItem rowItem:(id)rowItem{
    NSLog(@"点击了 %@",rowItem);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
